﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DALFactory;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class SkuBLL : IBaseInfoDetail
    {
        private static readonly IAlternateSkuDA alternateDA = DataAccess.CreateAlternateSkuDA();
        private static readonly ICartonDA cartonDA = DataAccess.CreateCartonDA();
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IEdiLogDA edilogDA = DataAccess.CreateEdiLogDA();
        private static readonly ILotTemplateDA iLotTemplateDA = DataAccess.CreateLotTemplateDA();
        private static readonly IInvSkuLocDA invSkuLocDA = DataAccess.CreateInvSkuLocDA();
        private static readonly IPackDA iPackDA = DataAccess.CreatePackDA();
        private static readonly ITariffDA iTariffDa = DataAccess.CreateTariffDA();
        private static readonly IItemNoDA itemNoDA = DataAccess.CreateItemNoDA();
        private static readonly ILocationDA locationDA = DataAccess.CreateLocationDA();
        private static readonly IOwnerDA ownerDA = DataAccess.CreateOwnerDA();
        private PubParasInfo pubParasInfo;
        private static readonly ISkuClassDA skuClassDA = DataAccess.CreateSkuClassDA();
        private static readonly ISkuDA skuDA = DataAccess.CreateSkuDA();
        private static readonly ISubstituteSkuDA substituteDA = DataAccess.CreateSubstituteSkuDA();
        private static readonly IZoneDA zoneDA = DataAccess.CreateZoneDA();

        public SkuBLL()
        {
            this.pubParasInfo = null;
        }

        public SkuBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public SkuBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string DeleteDetail(List<string> ownerID, List<string> skuID, List<string> pk3)
        {
            string temp = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                int i;
                if (ownerID.Count != skuID.Count)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2210_013", this.pubParasInfo.UserLanguage);
                }
                List<SkuInfo> skuInfos = new List<SkuInfo>();
                SkuInfo skuInfo = null;
                for (i = 0; i < ownerID.Count; i++)
                {
                    skuInfo = skuDA.GetSkuByID(dataBase, tran, ownerID[i], skuID[i], this.dataBaseID[0]);
                    skuInfo.AlternateSkuInfos = alternateDA.GetAlternateSkuListByID(dataBase, tran, ownerID[i], skuID[i], this.dataBaseID[0]);
                    skuInfo.SubstituteSkuInfos = substituteDA.GetSubstituteSkuListByID(dataBase, tran, ownerID[i], skuID[i], this.dataBaseID[0]);
                    skuInfos.Add(skuInfo);
                }
                AuditDataBLL auditDataBLL = new AuditDataBLL();
                substituteDA.DeleteSubstituteSku(dataBase, tran, ownerID, skuID, this.dataBaseID);
                alternateDA.DeleteAlternateSku(dataBase, tran, ownerID, skuID, this.dataBaseID);
                skuDA.DeleteSku(dataBase, tran, ownerID, skuID, this.dataBaseID);
                for (i = 0; i < ownerID.Count; i++)
                {
                    int j;
                    auditDataBLL.InsertAuditData<SkuInfo>(dataBase, tran, skuInfos[i], null, AuditAction.Delete, this.pubParasInfo.UserID, "SKU", this.dataBaseID);
                    if ((skuInfos[i].AlternateSkuInfos != null) && (skuInfos[i].AlternateSkuInfos.Count > 0))
                    {
                        j = 0;
                        while (j < skuInfos[i].AlternateSkuInfos.Count)
                        {
                            auditDataBLL.InsertAuditData<AlternateSkuInfo>(dataBase, tran, skuInfos[i].AlternateSkuInfos[j], null, AuditAction.Delete, this.pubParasInfo.UserID, "ALTERNATE_SKU", this.dataBaseID);
                            j++;
                        }
                    }
                    if ((skuInfos[i].SubstituteSkuInfos != null) && (skuInfos[i].SubstituteSkuInfos.Count > 0))
                    {
                        for (j = 0; j < skuInfos[i].SubstituteSkuInfos.Count; j++)
                        {
                            auditDataBLL.InsertAuditData<SubstituteSkuInfo>(dataBase, tran, skuInfos[i].SubstituteSkuInfos[j], null, AuditAction.Delete, this.pubParasInfo.UserID, "SUBSTITUTE_SKU", this.dataBaseID);
                        }
                    }
                    string CS00002 = temp;
                    temp = CS00002 + ownerID[i] + "," + skuID[i] + ";";
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            if (temp.Length > 0)
            {
                return temp.Substring(0, temp.Length - 1);
            }
            return "";
        }

        public DataSet GetAllDetailInfo()
        {
            return skuDA.GetAllSku(this.dataBaseID[0], this.pubParasInfo);
        }

        public DataSet GetDetaiInfolByQueryEntity(object obj)
        {
            SkuQueryEntity skuQuery = obj as SkuQueryEntity;
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(skuQuery.IsActive))
            {
                sqlWhere.Add(" SKU.IS_ACTIVE " + skuQuery.IsActive);
            }
            if (!string.IsNullOrEmpty(skuQuery.SkuID))
            {
                sqlWhere.Add(" SKU.SKU_ID " + skuQuery.SkuID);
            }
            if (!string.IsNullOrEmpty(skuQuery.OwnerID))
            {
                sqlWhere.Add(" SKU.OWNER_ID " + skuQuery.OwnerID);
            }
            if (!string.IsNullOrEmpty(skuQuery.PackID))
            {
                sqlWhere.Add(" SKU.PACK_ID " + skuQuery.PackID);
            }
            if (!string.IsNullOrEmpty(skuQuery.Descr))
            {
                sqlWhere.Add(" SKU.DESCR " + skuQuery.Descr);
            }
            if (!string.IsNullOrEmpty(skuQuery.LotTemplateID))
            {
                sqlWhere.Add(" SKU.LOT_TEMPLATE_ID " + skuQuery.LotTemplateID);
            }
            if (!string.IsNullOrEmpty(skuQuery.SkuClassID))
            {
                sqlWhere.Add(" SKU.SKU_CLASS_ID " + skuQuery.SkuClassID);
            }
            return skuDA.GetSkuByQueryList(sqlWhere, skuQuery, this.dataBaseID[0], this.pubParasInfo);
        }

        public object GetDetailInfoByID(string ownerID, string skuID, string pk3)
        {
            SkuInfo skuInfo = skuDA.GetSkuByID(ownerID, skuID, this.dataBaseID[0]);
            if (skuInfo != null)
            {
                skuInfo.AlternateSkuInfos = alternateDA.GetAlternateSkuListByID(ownerID, skuID, this.dataBaseID[0]);
                skuInfo.SubstituteSkuInfos = substituteDA.GetSubstituteSkuListByID(ownerID, skuID, this.dataBaseID[0]);
                skuInfo.InvSkuLocInfos = invSkuLocDA.GetInvSkuLocByID(ownerID, skuID, this.dataBaseID[0], this.pubParasInfo);
            }
            return skuInfo;
        }

        public List<object> GetDetailInfoListByID(string mainID, string subID)
        {
            return null;
        }

        public string InsertDetail(object obj)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            SkuInfo skuInfo = obj as SkuInfo;
            string skuID = string.Empty;
            try
            {
                if (skuInfo != null)
                {
                    int i;
                    if (!ownerDA.CheckTradePartnerIDUnique(skuInfo.OwnerID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_003", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.OwnerID });
                    }
                    else if (!commonMethod.CheckAuthorizationOwnerByUserID(this.pubParasInfo.UserID, skuInfo.OwnerID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_004", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.OwnerID });
                    }
                    if (skuDA.CheckSkuIDUnique(dataBase, tran, skuInfo.OwnerID, skuInfo.SkuID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_005", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.SkuID });
                    }
                    LocationInfo locationInfo = locationDA.GetLocationByID(skuInfo.PutawayLoc, this.dataBaseID[0]);
                    if ((locationInfo == null) || string.IsNullOrEmpty(locationInfo.Loc))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_006", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.PutawayLoc });
                    }
                    if (!string.IsNullOrEmpty(skuInfo.SkuClassID) && !skuClassDA.CheckSkuClassIDUnique(dataBase, tran, skuInfo.SkuClassID, skuInfo.OwnerID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_015", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.SkuClassID });
                    }
                    if (!DataAccess.CreatePackDA().CheckPackIDUnique(dataBase, tran, skuInfo.PackID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_007", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.PackID });
                    }
                    if (!DataAccess.CreateLotTemplateDA().CheckLotTemplateIDUnique(dataBase, tran, skuInfo.LotTemplateID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_008", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.LotTemplateID });
                    }
                    if (!string.IsNullOrEmpty(skuInfo.CartonGroup) && !cartonDA.CheckCartonUniqueByCartonGroup(dataBase, tran, skuInfo.CartonGroup, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_019", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.CartonGroup });
                    }
                    if (!string.IsNullOrEmpty(skuInfo.TariffID) && !iTariffDa.CheckTariffIDUnique(dataBase, tran, skuInfo.TariffID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_018", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.TariffID });
                    }
                    if (!string.IsNullOrEmpty(skuInfo.ItemNoID) && !itemNoDA.CheckItemNoIDUnique(dataBase, tran, skuInfo.ItemNoID, this.dataBaseID[0]))
                    {
                        throw new Exception("项号不存在,请重新输入!");
                    }
                    skuInfo.UpdatedBy = skuInfo.CreatedBy;
                    skuInfo.CreatedDate = DateTime.Now;
                    skuInfo.UpdatedDate = DateTime.Now;
                    skuDA.InsertSku(dataBase, tran, skuInfo, this.dataBaseID);
                    AuditDataBLL auditDataBLL = new AuditDataBLL();
                    auditDataBLL.InsertAuditData<SkuInfo>(dataBase, tran, null, skuInfo, AuditAction.Insert, this.pubParasInfo.UserID, "SKU", this.dataBaseID);
                    skuID = skuInfo.SkuID;
                    if ((skuInfo.AlternateSkuInfos != null) && (skuInfo.AlternateSkuInfos.Count > 0))
                    {
                        for (i = 0; i < skuInfo.AlternateSkuInfos.Count; i++)
                        {
                            if (alternateDA.CheckAlternateSkuIDUnique(dataBase, tran, skuInfo.AlternateSkuInfos[i].OwnerID, skuInfo.AlternateSkuInfos[i].SkuID, skuInfo.AlternateSkuInfos[i].AltSkuID, skuInfo.AlternateSkuInfos[i].VendorID, this.dataBaseID[0]))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F2210_009", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.AlternateSkuInfos[i].AltSkuID });
                            }
                            else
                            {
                                skuInfo.AlternateSkuInfos[i].CreatedDate = DateTime.Now;
                                skuInfo.AlternateSkuInfos[i].UpdatedDate = DateTime.Now;
                                skuInfo.AlternateSkuInfos[i].CreatedBy = this.pubParasInfo.UserID;
                                skuInfo.AlternateSkuInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                                alternateDA.InsertAlternateSku(dataBase, tran, skuInfo.AlternateSkuInfos[i], this.dataBaseID);
                                auditDataBLL.InsertAuditData<AlternateSkuInfo>(dataBase, tran, null, skuInfo.AlternateSkuInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "ALTERNATE_SKU", this.dataBaseID);
                            }
                        }
                    }
                    if ((skuInfo.SubstituteSkuInfos != null) && (skuInfo.SubstituteSkuInfos.Count > 0))
                    {
                        for (i = 0; i < skuInfo.SubstituteSkuInfos.Count; i++)
                        {
                            if (substituteDA.CheckSubstituteSkuIDUnique(dataBase, tran, skuInfo.SubstituteSkuInfos[i].OwnerID, skuInfo.SubstituteSkuInfos[i].SkuID, skuInfo.SubstituteSkuInfos[i].SubstituteSkuID, this.dataBaseID[0]))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F2210_010", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.SubstituteSkuInfos[i].SubstituteSkuID });
                            }
                            else
                            {
                                skuInfo.SubstituteSkuInfos[i].CreatedDate = DateTime.Now;
                                skuInfo.SubstituteSkuInfos[i].UpdatedDate = DateTime.Now;
                                skuInfo.SubstituteSkuInfos[i].CreatedBy = this.pubParasInfo.UserID;
                                skuInfo.SubstituteSkuInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                                substituteDA.InsertSubstituteSku(dataBase, tran, skuInfo.SubstituteSkuInfos[i], this.dataBaseID);
                                auditDataBLL.InsertAuditData<SubstituteSkuInfo>(dataBase, tran, null, skuInfo.SubstituteSkuInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "SUBSTITUTE_SKU", this.dataBaseID);
                            }
                        }
                    }
                    tran.Commit();
                }
                return skuID;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return skuID;
        }

        public string InsertSkuByWebService(List<SkuInfo> skuinfo)
        {
            EdiLogInfo edilogInfo;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string skuID = "OK";
            SkuInfo skuInfoEx = null;
            List<EdiLogInfo> edilogInfoList = new List<EdiLogInfo>();
            try
            {
                foreach (SkuInfo info in skuinfo)
                {
                    skuInfoEx = info;
                    if (!string.IsNullOrEmpty(info.SkuClassID))
                    {
                        SkuClassInfo skuClassInfo;
                        if (!skuClassDA.CheckSkuClassIDUnique(dataBase, tran, info.SkuClassID, "1000", this.dataBaseID[0]))
                        {
                            skuClassInfo = new SkuClassInfo {
                                SkuClassID = info.SkuClassID,
                                OwnerID = "1000",
                                Descr = info.Udf9,
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            skuClassDA.InsertSkuClass(dataBase, tran, skuClassInfo, this.dataBaseID);
                        }
                        if (!skuClassDA.CheckSkuClassIDUnique(dataBase, tran, info.SkuClassID, "3000", this.dataBaseID[0]))
                        {
                            skuClassInfo = new SkuClassInfo {
                                SkuClassID = info.SkuClassID,
                                OwnerID = "3000",
                                Descr = info.Udf9,
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            skuClassDA.InsertSkuClass(dataBase, tran, skuClassInfo, this.dataBaseID);
                        }
                        if (!skuClassDA.CheckSkuClassIDUnique(dataBase, tran, info.SkuClassID, "9000", this.dataBaseID[0]))
                        {
                            skuClassInfo = new SkuClassInfo {
                                SkuClassID = info.SkuClassID,
                                OwnerID = "9000",
                                Descr = info.Udf9,
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            skuClassDA.InsertSkuClass(dataBase, tran, skuClassInfo, this.dataBaseID);
                        }
                        info.Udf9 = "";
                    }
                    LocationInfo locationInfo = locationDA.GetLocationByID(info.PutawayLoc, this.dataBaseID[0]);
                    if ((locationInfo == null) || string.IsNullOrEmpty(locationInfo.Loc))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_006", this.pubParasInfo.UserLanguage, new List<string> { info.PutawayLoc });
                    }
                    string AltSkuID = info.Udf10;
                    info.Udf10 = "";
                    if (skuDA.CheckSkuIDUnique(dataBase, tran, "1000", info.SkuID, this.dataBaseID[0]))
                    {
                        info.OwnerID = "1000";
                        skuDA.UpdateSku(dataBase, tran, info, this.dataBaseID);
                    }
                    else
                    {
                        info.OwnerID = "1000";
                        skuDA.InsertSku(dataBase, tran, info, this.dataBaseID);
                    }
                    if (skuDA.CheckSkuIDUnique(dataBase, tran, "3000", info.SkuID, this.dataBaseID[0]))
                    {
                        info.OwnerID = "3000";
                        skuDA.UpdateSku(dataBase, tran, info, this.dataBaseID);
                    }
                    else
                    {
                        info.OwnerID = "3000";
                        skuDA.InsertSku(dataBase, tran, info, this.dataBaseID);
                    }
                    if (skuDA.CheckSkuIDUnique(dataBase, tran, "9000", info.SkuID, this.dataBaseID[0]))
                    {
                        info.OwnerID = "9000";
                        skuDA.UpdateSku(dataBase, tran, info, this.dataBaseID);
                    }
                    else
                    {
                        info.OwnerID = "9000";
                        skuDA.InsertSku(dataBase, tran, info, this.dataBaseID);
                    }
                    if (!string.IsNullOrEmpty(AltSkuID))
                    {
                        AlternateSkuInfo altSku;
                        if (!alternateDA.CheckAlternateSkuIDUnique("1000", info.SkuID, AltSkuID, "", this.dataBaseID[0]))
                        {
                            altSku = new AlternateSkuInfo {
                                OwnerID = "1000",
                                SkuID = info.SkuID,
                                AltSkuID = AltSkuID,
                                VendorID = "",
                                PackID = "STD",
                                DefaultUomID = "EA",
                                Type = "Vendor",
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            alternateDA.InsertAlternateSku(dataBase, tran, altSku, this.dataBaseID);
                        }
                        if (!alternateDA.CheckAlternateSkuIDUnique("3000", info.SkuID, AltSkuID, "", this.dataBaseID[0]))
                        {
                            altSku = new AlternateSkuInfo {
                                OwnerID = "3000",
                                SkuID = info.SkuID,
                                AltSkuID = AltSkuID,
                                VendorID = "",
                                PackID = "STD",
                                DefaultUomID = "EA",
                                Type = "Vendor",
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            alternateDA.InsertAlternateSku(dataBase, tran, altSku, this.dataBaseID);
                        }
                        if (!alternateDA.CheckAlternateSkuIDUnique("9000", info.SkuID, AltSkuID, "", this.dataBaseID[0]))
                        {
                            altSku = new AlternateSkuInfo {
                                OwnerID = "9000",
                                SkuID = info.SkuID,
                                AltSkuID = AltSkuID,
                                VendorID = "",
                                PackID = "STD",
                                DefaultUomID = "EA",
                                Type = "Vendor",
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            alternateDA.InsertAlternateSku(dataBase, tran, altSku, this.dataBaseID);
                        }
                    }
                    edilogInfo = new EdiLogInfo {
                        WhID = "",
                        LogDate = DateTime.Now,
                        IsSuccess = "成功",
                        LogDescr = "货品" + info.SkuID + "插入成功",
                        UserID = "CEAWebService",
                        Udf1 = "新增",
                        Udf2 = "货品名称:" + info.SkuID,
                        Udf3 = "货品资料",
                        Udf4 = "产品描述:" + info.Descr
                    };
                    edilogInfoList.Add(edilogInfo);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                edilogInfoList = new List<EdiLogInfo>();
                edilogInfo = new EdiLogInfo {
                    WhID = "",
                    LogDate = DateTime.Now,
                    IsSuccess = "异常",
                    LogDescr = "货品" + skuInfoEx.SkuID + "插入失败:" + ex.Message,
                    UserID = "CEAWebService",
                    Udf1 = "新增",
                    Udf2 = "货品名称:" + skuInfoEx.SkuID,
                    Udf3 = "货品资料",
                    Udf4 = "产品描述:" + skuInfoEx.Descr
                };
                edilogInfoList.Add(edilogInfo);
                skuID = ex.Message;
            }
            finally
            {
                edilogDA.InsertEdiLogs(edilogInfoList);
                conn.Close();
            }
            return skuID;
        }

        public string SkuImportByData(string[][] ImportByData, string IsUpdate)
        {
            Exception ex;
            string SkuIDTrue = string.Empty;
            string SkuIDFalse = string.Empty;
            string StrGlobal = ConfigurationManager.AppSettings["GLOBAL_SETTING"];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                List<TradePartnerInfo> TradePartnerInfoList = new List<TradePartnerInfo>();
                SysSettingInfo sysSettingInfo = DataAccess.CreateSysSettingDA().GetSysSettingByID(dataBase, tran, "SetBCode10EqSkuIDWhenImport", this.dataBaseID[0], this.pubParasInfo);
                bool setBCode10EqualToSkuID = false;
                if (sysSettingInfo.Value == "Y")
                {
                    setBCode10EqualToSkuID = true;
                }
                for (int i = 1; ImportByData.Length > i; i++)
                {
                    SkuInfo SkuInfo;
                    string CS00004;
                    SkuInfo = new SkuInfo();
                    SkuInfo.IsActive = "Y";
                    SkuInfo.UpdatedBy = SkuInfo.CreatedBy;
                    SkuInfo.CartonGroup = "";
                    if (string.IsNullOrEmpty(SkuInfo.PackID))
                    {
                        SkuInfo.PackID = "STD";
                    }
                    if (string.IsNullOrEmpty(SkuInfo.LotTemplateID))
                    {
                        SkuInfo.LotTemplateID = "STD";
                    }
                    SkuInfo.HazmatCode = "";
                    SkuInfo.ShelfLifeCodeType = "";
                    SkuInfo.IsSalePromption = "";
                    SkuInfo.ReceiptValidationTemplate = "";
                    SkuInfo.CalculatePutawayLocation = "";
                    SkuInfo.ReceiptValidationID = "";
                    SkuInfo.PutawayLoc = "Stage";
                    SkuInfo.ReceiptInspectionLoc = "";
                    SkuInfo.ReturnsLoc = "";
                    SkuInfo.QcLoc = "";
                    SkuInfo.CcDiscrepanCyrule = "";
                    SkuInfo.ItemNoID = "";
                    for (int n = 0; ImportByData[i].Length > n; n++)
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(ImportByData[i][n]))
                            {
                                switch (ImportByData[0][n])
                                {
                                    case "货主代码":
                                    {
                                        SkuInfo.OwnerID = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "货品代码":
                                    {
                                        SkuInfo.SkuID = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "描述":
                                    {
                                        SkuInfo.Descr = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "描述2":
                                    {
                                        SkuInfo.Descr2 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "包装":
                                    {
                                        SkuInfo.PackID = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "批次模板":
                                    {
                                        SkuInfo.LotTemplateID = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "价目表":
                                    {
                                        SkuInfo.TariffID = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "货品类型":
                                    {
                                        SkuInfo.SkuClassID = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "产品组":
                                    {
                                        SkuInfo.SkuGroup = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "产品组2":
                                    {
                                        SkuInfo.SkuGroup2 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "运输方式":
                                    {
                                        SkuInfo.TransportMode = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "货运类别":
                                    {
                                        SkuInfo.FreightClass = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "ABC":
                                    {
                                        SkuInfo.Abc = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "长":
                                    {
                                        if (!string.IsNullOrEmpty(ImportByData[i][n].Trim()))
                                        {
                                            SkuInfo.Length = Convert.ToSingle(ImportByData[i][n].Trim());
                                        }
                                        continue;
                                    }
                                    case "宽":
                                    {
                                        if (!string.IsNullOrEmpty(ImportByData[i][n].Trim()))
                                        {
                                            SkuInfo.Width = Convert.ToSingle(ImportByData[i][n].Trim());
                                        }
                                        continue;
                                    }
                                    case "高":
                                    {
                                        if (!string.IsNullOrEmpty(ImportByData[i][n].Trim()))
                                        {
                                            SkuInfo.Height = Convert.ToSingle(ImportByData[i][n].Trim());
                                        }
                                        continue;
                                    }
                                    case "体积":
                                    {
                                        if (!string.IsNullOrEmpty(ImportByData[i][n].Trim()))
                                        {
                                            SkuInfo.Cube = Convert.ToSingle(ImportByData[i][n].Trim());
                                        }
                                        continue;
                                    }
                                    case "毛重":
                                    {
                                        if (!string.IsNullOrEmpty(ImportByData[i][n].Trim()))
                                        {
                                            SkuInfo.GrossWgt = Convert.ToSingle(ImportByData[i][n].Trim());
                                        }
                                        continue;
                                    }
                                    case "净重":
                                    {
                                        if (!string.IsNullOrEmpty(ImportByData[i][n].Trim()))
                                        {
                                            SkuInfo.NetWgt = Convert.ToSingle(ImportByData[i][n].Trim());
                                        }
                                        continue;
                                    }
                                    case "皮重":
                                    {
                                        if (!string.IsNullOrEmpty(ImportByData[i][n].Trim()))
                                        {
                                            SkuInfo.TareWgt = Convert.ToSingle(ImportByData[i][n].Trim());
                                        }
                                        continue;
                                    }
                                    case "项号":
                                    {
                                        SkuInfo.ItemNoID = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "条形码":
                                    {
                                        SkuInfo.BUdf1 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "尺码":
                                    {
                                        SkuInfo.SkuSize = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "颜色":
                                    {
                                        SkuInfo.SkuColor = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "型号":
                                    {
                                        SkuInfo.SkuStyle = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "成本价格":
                                    {
                                        SkuInfo.CostPrice = Convert.ToDecimal(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "销售价格":
                                    {
                                        SkuInfo.SalePrice = Convert.ToDecimal(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "净价":
                                    {
                                        SkuInfo.NetPrice = Convert.ToDecimal(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "保质期天数":
                                    {
                                        SkuInfo.DaysToExpire = Convert.ToInt32(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "最小订货量":
                                    {
                                        SkuInfo.ReorderQty = Convert.ToDecimal(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "保质期控制":
                                    {
                                        SkuInfo.ShelfLifeIndicator = Convert.ToString(ImportByData[i][n].Trim()).ToUpper();
                                        continue;
                                    }
                                    case "保质期类型":
                                    {
                                        SkuInfo.ShelfLifeCodeType = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "入库保质期天数":
                                    {
                                        SkuInfo.ShelfLifeOnReceiving = Convert.ToInt32(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "出库保质期天数":
                                    {
                                        SkuInfo.ShelfLife = Convert.ToInt32(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "危险品代码":
                                    {
                                        SkuInfo.HazmatCode = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "海关代码":
                                    {
                                        SkuInfo.CustomSkuNo = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "原产国":
                                    {
                                        SkuInfo.CountryOfOrigin = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "促销品":
                                    {
                                        SkuInfo.IsSalePromption = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "备注":
                                    {
                                        SkuInfo.Remark2 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义01":
                                    {
                                        SkuInfo.Udf1 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义02":
                                    {
                                        SkuInfo.Udf2 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义03":
                                    {
                                        SkuInfo.Udf3 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义04":
                                    {
                                        SkuInfo.Udf4 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义05":
                                    {
                                        SkuInfo.Udf5 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义06":
                                    {
                                        SkuInfo.Udf6 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义07":
                                    {
                                        SkuInfo.Udf7 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义08":
                                    {
                                        SkuInfo.Udf8 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义09":
                                    {
                                        SkuInfo.Udf9 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "自定义10":
                                    {
                                        SkuInfo.Udf10 = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "创建人":
                                    {
                                        SkuInfo.CreatedBy = ImportByData[i][n].Trim();
                                        continue;
                                    }
                                    case "收货验证规则":
                                    {
                                        SkuInfo.ReceiptValidationID = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "上架规则":
                                    {
                                        SkuInfo.PutawayRuleID = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "预分配规则":
                                    {
                                        SkuInfo.PreallocateRuleID = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "分配规则":
                                    {
                                        SkuInfo.AllocateRuleID = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "周转规则":
                                    {
                                        SkuInfo.RotationRuleID = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "上架区":
                                    {
                                        SkuInfo.ZoneID = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "上架货位":
                                    {
                                        SkuInfo.PutawayLoc = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "入库质检货位":
                                    {
                                        SkuInfo.ReceiptInspectionLoc = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "出库质检货位":
                                    {
                                        SkuInfo.QcLocOut = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "退货接收货位":
                                    {
                                        SkuInfo.ReturnsLoc = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "最小库存":
                                    {
                                        SkuInfo.MinQty = Convert.ToDecimal(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "最大库存":
                                    {
                                        SkuInfo.MaxQty = Convert.ToDecimal(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "订货点":
                                    {
                                        SkuInfo.ReorderPoint = Convert.ToInt32(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "计算上架时机":
                                    {
                                        SkuInfo.CalculatePutawayLocation = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "循环盘点级别":
                                    {
                                        SkuInfo.Abc = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                    case "循环盘点差异处理规则":
                                    {
                                        SkuInfo.CcDiscrepanCyrule = Convert.ToString(ImportByData[i][n].Trim());
                                        continue;
                                    }
                                }
                            }
                        }
                        catch (Exception exception1)
                        {
                            ex = exception1;
                            if (!string.IsNullOrEmpty(SkuInfo.SkuID))
                            {
                                CS00004 = SkuIDFalse;
                                SkuIDFalse = CS00004 + SkuInfo.SkuID + "(数据内容异常,导入失败)" + ex.Message + ";<br/>";
                            }
                        }
                    }
                    if (setBCode10EqualToSkuID)
                    {
                        SkuInfo.BUdf10 = SkuInfo.SkuID;
                    }
                    if (string.IsNullOrEmpty(SkuInfo.SkuGroup))
                    {
                        SkuInfo.SkuGroup = "";
                    }
                    if (string.IsNullOrEmpty(SkuInfo.SkuClassID))
                    {
                        SkuInfo.SkuClassID = "";
                    }
                    if (string.IsNullOrEmpty(SkuInfo.CreatedBy))
                    {
                        SkuInfo.CreatedBy = this.pubParasInfo.UserID;
                    }
                    if (string.IsNullOrEmpty(SkuInfo.UpdatedBy))
                    {
                        SkuInfo.UpdatedBy = SkuInfo.CreatedBy;
                    }
                    if (!string.IsNullOrEmpty(SkuInfo.SkuID))
                    {
                        SkuInfo.SkuID = SkuInfo.SkuID.Trim();
                        if (!string.IsNullOrEmpty(SkuInfo.ItemNoID) && !itemNoDA.CheckItemNoIDUnique(dataBase, tran, SkuInfo.ItemNoID, this.dataBaseID[0]))
                        {
                            CS00004 = SkuIDFalse;
                            SkuIDFalse = CS00004 + SkuInfo.SkuID + "(货品 " + SkuInfo.SkuID + " 项号不存在);<br/>";
                        }
                        try
                        {
                            if (this.pubParasInfo.CurrentWH == StrGlobal)
                            {
                                if (!ownerDA.CheckTradePartnerIDUnique(dataBase, tran, SkuInfo.OwnerID, this.dataBaseID[0]))
                                {
                                    CS00004 = SkuIDFalse;
                                    SkuIDFalse = CS00004 + SkuInfo.SkuID + "(货主 " + SkuInfo.OwnerID + " 不存在);<br/>";
                                }
                                if (!(string.IsNullOrEmpty(SkuInfo.SkuClassID) || skuClassDA.CheckSkuClassIDUnique(dataBase, tran, SkuInfo.SkuClassID, SkuInfo.OwnerID, this.dataBaseID[0])))
                                {
                                    CS00004 = SkuIDFalse;
                                    SkuIDFalse = CS00004 + SkuInfo.SkuID + "(货品分类 " + SkuInfo.SkuClassID + " 不存在);<br/>";
                                }
                                else if (!iLotTemplateDA.CheckLotTemplateIDUnique(dataBase, tran, SkuInfo.LotTemplateID, this.dataBaseID[0]))
                                {
                                    CS00004 = SkuIDFalse;
                                    SkuIDFalse = CS00004 + SkuInfo.SkuID + "(批次模板 " + SkuInfo.LotTemplateID + " 不存在);<br/>";
                                }
                                else if (!iPackDA.CheckPackIDUnique(dataBase, tran, SkuInfo.PackID, this.dataBaseID[0]))
                                {
                                    CS00004 = SkuIDFalse;
                                    SkuIDFalse = CS00004 + SkuInfo.SkuID + "(包装 " + SkuInfo.PackID + " 不存在);<br/>";
                                }
                                else if (skuDA.CheckSkuIDUnique(dataBase, tran, SkuInfo.OwnerID, SkuInfo.SkuID, this.dataBaseID[0]))
                                {
                                    if (IsUpdate == "Y")
                                    {
                                        SkuInfo currSkuInfo = skuDA.GetSkuByID(dataBase, tran, SkuInfo.OwnerID, SkuInfo.SkuID, this.dataBaseID[0]);
                                        SkuInfo.ReceiptValidationID = string.IsNullOrEmpty(SkuInfo.ReceiptValidationID) ? currSkuInfo.ReceiptValidationID : SkuInfo.ReceiptValidationID;
                                        SkuInfo.PutawayRuleID = string.IsNullOrEmpty(SkuInfo.PutawayRuleID) ? currSkuInfo.PutawayRuleID : SkuInfo.PutawayRuleID;
                                        SkuInfo.PreallocateRuleID = string.IsNullOrEmpty(SkuInfo.PreallocateRuleID) ? currSkuInfo.PreallocateRuleID : SkuInfo.PreallocateRuleID;
                                        SkuInfo.AllocateRuleID = string.IsNullOrEmpty(SkuInfo.AllocateRuleID) ? currSkuInfo.AllocateRuleID : SkuInfo.AllocateRuleID;
                                        SkuInfo.RotationRuleID = string.IsNullOrEmpty(SkuInfo.RotationRuleID) ? currSkuInfo.RotationRuleID : SkuInfo.RotationRuleID;
                                        SkuInfo.ReceiptInspectionLoc = string.IsNullOrEmpty(SkuInfo.ReceiptInspectionLoc) ? currSkuInfo.ReceiptInspectionLoc : SkuInfo.ReceiptInspectionLoc;
                                        SkuInfo.QcLocOut = string.IsNullOrEmpty(SkuInfo.QcLocOut) ? currSkuInfo.QcLocOut : SkuInfo.QcLocOut;
                                        SkuInfo.ReturnsLoc = string.IsNullOrEmpty(SkuInfo.ReturnsLoc) ? currSkuInfo.ReturnsLoc : SkuInfo.ReturnsLoc;
                                        SkuInfo.ZoneID = string.IsNullOrEmpty(SkuInfo.ZoneID) ? currSkuInfo.ZoneID : SkuInfo.ZoneID;
                                        SkuInfo.PutawayLoc = string.IsNullOrEmpty(SkuInfo.PutawayLoc) ? currSkuInfo.PutawayLoc : SkuInfo.PutawayLoc;
                                        SkuInfo.ReceiptInspectionLoc = string.IsNullOrEmpty(SkuInfo.ReceiptInspectionLoc) ? currSkuInfo.ReceiptInspectionLoc : SkuInfo.ReceiptInspectionLoc;
                                        SkuInfo.QcLoc = string.IsNullOrEmpty(SkuInfo.QcLoc) ? currSkuInfo.QcLoc : SkuInfo.QcLoc;
                                        SkuInfo.MinQty = (SkuInfo.MinQty == 0M) ? currSkuInfo.MinQty : SkuInfo.MinQty;
                                        SkuInfo.MaxQty = (SkuInfo.MaxQty == 0M) ? currSkuInfo.MaxQty : SkuInfo.MaxQty;
                                        SkuInfo.ReorderQty = (SkuInfo.ReorderQty == 0M) ? currSkuInfo.ReorderQty : SkuInfo.ReorderQty;
                                        SkuInfo.CalculatePutawayLocation = string.IsNullOrEmpty(SkuInfo.CalculatePutawayLocation) ? currSkuInfo.CalculatePutawayLocation : SkuInfo.CalculatePutawayLocation;
                                        SkuInfo.Abc = string.IsNullOrEmpty(SkuInfo.Abc) ? currSkuInfo.Abc : SkuInfo.Abc;
                                        SkuInfo.CcDiscrepanCyrule = string.IsNullOrEmpty(SkuInfo.CcDiscrepanCyrule) ? currSkuInfo.CcDiscrepanCyrule : SkuInfo.CcDiscrepanCyrule;
                                        if (SkuInfo.Length == 0f)
                                        {
                                            SkuInfo.Length = currSkuInfo.Length;
                                        }
                                        if (SkuInfo.Width == 0f)
                                        {
                                            SkuInfo.Width = currSkuInfo.Width;
                                        }
                                        if (SkuInfo.Height == 0f)
                                        {
                                            SkuInfo.Height = currSkuInfo.Height;
                                        }
                                        if (SkuInfo.Cube == 0f)
                                        {
                                            SkuInfo.Cube = currSkuInfo.Cube;
                                        }
                                        if (SkuInfo.GrossWgt == 0f)
                                        {
                                            SkuInfo.GrossWgt = currSkuInfo.GrossWgt;
                                        }
                                        if (SkuInfo.NetWgt == 0f)
                                        {
                                            SkuInfo.NetWgt = currSkuInfo.NetWgt;
                                        }
                                        if (SkuInfo.TareWgt == 0f)
                                        {
                                            SkuInfo.TareWgt = currSkuInfo.TareWgt;
                                        }
                                        if (skuDA.UpdateSku(dataBase, tran, SkuInfo, this.dataBaseID) > 0)
                                        {
                                            SkuIDFalse = SkuIDFalse + SkuInfo.SkuID + "(数据已经更新);<br/>";
                                        }
                                    }
                                    else
                                    {
                                        SkuIDFalse = SkuIDFalse + SkuInfo.SkuID + "(数据已经存在,导入失败);<br/>";
                                    }
                                }
                                else
                                {
                                    TradePartnerInfo tradePartnerInfo = null;
                                    for (int b = 0; TradePartnerInfoList.Count > b; b++)
                                    {
                                        if (TradePartnerInfoList[b].OwnerID == SkuInfo.OwnerID)
                                        {
                                            tradePartnerInfo = TradePartnerInfoList[b];
                                            break;
                                        }
                                    }
                                    if (tradePartnerInfo == null)
                                    {
                                        tradePartnerInfo = ownerDA.GetTradePartnerByID(dataBase, tran, SkuInfo.OwnerID, this.dataBaseID[0]);
                                        TradePartnerInfoList.Add(tradePartnerInfo);
                                    }
                                    SkuInfo.ReceiptValidationID = tradePartnerInfo.ReceiptValidationID;
                                    SkuInfo.PutawayRuleID = tradePartnerInfo.DefaultPutawayRuleID;
                                    SkuInfo.PreallocateRuleID = tradePartnerInfo.DefaultPreallocateRuleID;
                                    SkuInfo.AllocateRuleID = tradePartnerInfo.DefaultAllocateRuleID;
                                    SkuInfo.RotationRuleID = tradePartnerInfo.DefaultRotationRuleID;
                                    SkuInfo.CalculatePutawayLocation = tradePartnerInfo.CalculatePutawayLocation;
                                    SkuInfo.ReceiptInspectionLoc = tradePartnerInfo.DefaultQcLoc;
                                    SkuInfo.QcLocOut = tradePartnerInfo.DefaultQcLocOut;
                                    SkuInfo.ReturnsLoc = tradePartnerInfo.DefaultReturnsLoc;
                                    if (skuDA.InsertSku(dataBase, tran, SkuInfo, this.dataBaseID) > 0)
                                    {
                                        SkuIDTrue = SkuIDTrue + SkuInfo.SkuID + ";";
                                    }
                                }
                            }
                            else if (skuDA.CheckSkuIDUnique(dataBase, tran, SkuInfo.OwnerID, SkuInfo.SkuID, this.dataBaseID[0]))
                            {
                                SkuInfo skuInfo = skuDA.GetSkuByID(dataBase, tran, SkuInfo.OwnerID, SkuInfo.SkuID, this.dataBaseID[0]);
                                skuInfo.ReceiptValidationID = SkuInfo.ReceiptValidationID;
                                skuInfo.PutawayRuleID = SkuInfo.PutawayRuleID;
                                skuInfo.PreallocateRuleID = SkuInfo.PreallocateRuleID;
                                skuInfo.AllocateRuleID = SkuInfo.AllocateRuleID;
                                skuInfo.ZoneID = SkuInfo.ZoneID;
                                skuInfo.PutawayLoc = SkuInfo.PutawayLoc;
                                skuInfo.ReceiptInspectionLoc = SkuInfo.ReceiptInspectionLoc;
                                skuInfo.QcLocOut = SkuInfo.QcLocOut;
                                skuInfo.ReturnsLoc = SkuInfo.ReturnsLoc;
                                skuInfo.MinQty = SkuInfo.MinQty;
                                skuInfo.MaxQty = SkuInfo.MaxQty;
                                skuInfo.ReorderQty = SkuInfo.ReorderQty;
                                skuInfo.CalculatePutawayLocation = SkuInfo.CalculatePutawayLocation;
                                skuInfo.Abc = SkuInfo.Abc;
                                skuInfo.CcDiscrepanCyrule = SkuInfo.CcDiscrepanCyrule;
                                if (!string.IsNullOrEmpty(SkuInfo.RotationRuleID))
                                {
                                    skuInfo.RotationRuleID = SkuInfo.RotationRuleID;
                                }
                                if (skuDA.UpdateSku(dataBase, tran, skuInfo, this.dataBaseID) > 0)
                                {
                                    SkuIDFalse = SkuIDFalse + SkuInfo.SkuID + "(数据已经更新);<br/>";
                                }
                                else
                                {
                                    SkuIDFalse = SkuIDFalse + SkuInfo.SkuID + "(数据不存在);<br/>";
                                }
                            }
                        }
                        catch (Exception exception2)
                        {
                            ex = exception2;
                            if (!string.IsNullOrEmpty(SkuInfo.SkuID))
                            {
                                CS00004 = SkuIDFalse;
                                SkuIDFalse = CS00004 + SkuInfo.SkuID + "(数据交互时出现异常,导入失败)" + ex.Message + ";<br/>";
                            }
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception exception3)
            {
                ex = exception3;
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return SkuIDFalse;
        }

        public string UpdateDetail(object obj)
        {
            string skuID = string.Empty;
            try
            {
                SkuInfo skuInfo = obj as SkuInfo;
                LocationInfo locationInfo = locationDA.GetLocationByID(skuInfo.PutawayLoc, this.dataBaseID[0], this.pubParasInfo);
                if ((locationInfo == null) || string.IsNullOrEmpty(locationInfo.Loc))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2210_011", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.PutawayLoc });
                }
                if (!string.IsNullOrEmpty(skuInfo.ZoneID))
                {
                    ZoneInfo zoneInfo = zoneDA.GetZoneByID(skuInfo.ZoneID, this.dataBaseID[0]);
                    if ((zoneInfo == null) || string.IsNullOrEmpty(zoneInfo.ZoneID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2210_012", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.ZoneID });
                    }
                }
                if (!DataAccess.CreatePackDA().CheckPackIDUnique(skuInfo.PackID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2210_007", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.PackID });
                }
                if (!string.IsNullOrEmpty(skuInfo.SkuClassID) && !skuClassDA.CheckSkuClassIDUnique(skuInfo.SkuClassID, skuInfo.OwnerID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2210_015", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.SkuClassID });
                }
                if (!DataAccess.CreateLotTemplateDA().CheckLotTemplateIDUnique(skuInfo.LotTemplateID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2210_008", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.LotTemplateID });
                }
                if (!string.IsNullOrEmpty(skuInfo.TariffID) && !iTariffDa.CheckTariffIDUnique(skuInfo.TariffID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2210_018", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.TariffID });
                }
                if (!string.IsNullOrEmpty(skuInfo.CartonGroup) && !cartonDA.CheckCartonUniqueByCartonGroup(skuInfo.CartonGroup, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2210_019", this.pubParasInfo.UserLanguage, new List<string> { skuInfo.CartonGroup });
                }
                if (!string.IsNullOrEmpty(skuInfo.ItemNoID) && !itemNoDA.CheckItemNoIDUnique(skuInfo.ItemNoID, this.dataBaseID[0]))
                {
                    throw new Exception("项号不存在,请重新输入!");
                }
                SkuInfo oldSkuInfo = skuDA.GetSkuByID(skuInfo.OwnerID, skuInfo.SkuID, this.dataBaseID[0]);
                if (skuDA.UpdateSku(skuInfo, this.dataBaseID) > 0)
                {
                    new AuditDataBLL().InsertAuditData<SkuInfo>(oldSkuInfo, skuInfo, AuditAction.Update, this.pubParasInfo.UserID, "SKU", this.dataBaseID[0]);
                    skuID = skuInfo.SkuID;
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return skuID;
        }

        public string UpdateIsActive(List<string> ownerID, List<string> skuID, string isActive)
        {
            string temp = string.Empty;
            string StrGlobal = ConfigurationManager.AppSettings["GLOBAL_SETTING"];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                int i;
                if (ownerID.Count != skuID.Count)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2210_013", this.pubParasInfo.UserLanguage);
                }
                List<SkuInfo> skuInfos = new List<SkuInfo>();
                SkuInfo skuInfo = null;
                for (i = 0; i < ownerID.Count; i++)
                {
                    skuInfo = skuDA.GetSkuByID(dataBase, tran, ownerID[i], skuID[i], this.dataBaseID[0]);
                    skuInfo.AlternateSkuInfos = alternateDA.GetAlternateSkuListByID(dataBase, tran, ownerID[i], skuID[i], this.dataBaseID[0]);
                    skuInfo.SubstituteSkuInfos = substituteDA.GetSubstituteSkuListByID(dataBase, tran, ownerID[i], skuID[i], this.dataBaseID[0]);
                    skuInfos.Add(skuInfo);
                }
                AuditDataBLL auditDataBLL = new AuditDataBLL();
                if (this.pubParasInfo.CurrentWH == StrGlobal)
                {
                    skuDA.UpdateIsActive(dataBase, tran, ownerID, skuID, isActive, this.dataBaseID, this.pubParasInfo);
                }
                else
                {
                    List<string> gInitLocal13 = new List<string> {
                        this.dataBaseID[0]
                    };
                    skuDA.UpdateIsActive(dataBase, tran, ownerID, skuID, isActive, gInitLocal13, this.pubParasInfo);
                }
                for (i = 0; i < ownerID.Count; i++)
                {
                    string CS00002 = temp;
                    temp = CS00002 + ownerID[i] + "," + skuID[i] + ";";
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            if (temp.Length > 0)
            {
                return temp.Substring(0, temp.Length - 1);
            }
            return "";
        }

        public string UpdateSkuWebService(List<SkuInfo> skuInfo)
        {
            EdiLogInfo edilogInfo;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string skuID = "OK";
            SkuInfo skuInfoEx = null;
            List<EdiLogInfo> edilogInfoList = new List<EdiLogInfo>();
            string strOwnerID = string.Empty;
            string strSkuID = string.Empty;
            try
            {
                foreach (SkuInfo info in skuInfo)
                {
                    strOwnerID = info.Descr;
                    strSkuID = info.SkuID;
                    skuInfoEx = skuDA.GetSkuByID(info.OwnerID, info.SkuID, this.dataBaseID[0]);
                    if (skuInfoEx == null)
                    {
                        throw new Exception("未找到匹配的单据");
                    }
                    if (!string.IsNullOrEmpty(info.IsActive))
                    {
                        skuInfoEx.IsActive = info.IsActive;
                    }
                    if (!string.IsNullOrEmpty(info.Descr))
                    {
                        skuInfoEx.Descr = info.Descr;
                    }
                    if (!string.IsNullOrEmpty(info.SkuGroup))
                    {
                        skuInfoEx.SkuGroup = info.SkuGroup;
                    }
                    if (!string.IsNullOrEmpty(info.SkuGroup2))
                    {
                        skuInfoEx.SkuGroup2 = info.SkuGroup2;
                    }
                    if (!string.IsNullOrEmpty(info.Udf1))
                    {
                        skuInfoEx.Udf1 = info.Udf1;
                    }
                    if (!string.IsNullOrEmpty(info.Udf2))
                    {
                        skuInfoEx.Udf2 = info.Udf2;
                    }
                    if (!string.IsNullOrEmpty(info.Udf3))
                    {
                        skuInfoEx.Udf3 = info.Udf3;
                    }
                    if (!string.IsNullOrEmpty(info.Udf4))
                    {
                        skuInfoEx.Udf4 = info.Udf4;
                    }
                    if (!string.IsNullOrEmpty(info.Udf5))
                    {
                        skuInfoEx.Udf5 = info.Udf5;
                    }
                    if (!string.IsNullOrEmpty(info.SkuClassID))
                    {
                        SkuClassInfo skuClassInfo;
                        skuInfoEx.SkuClassID = info.SkuClassID;
                        if (!skuClassDA.CheckSkuClassIDUnique(dataBase, tran, info.SkuClassID, "1000", this.dataBaseID[0]))
                        {
                            skuClassInfo = new SkuClassInfo {
                                SkuClassID = info.SkuClassID,
                                OwnerID = "1000",
                                Descr = info.Udf9,
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            skuClassDA.InsertSkuClass(dataBase, tran, skuClassInfo, this.dataBaseID);
                        }
                        if (!skuClassDA.CheckSkuClassIDUnique(dataBase, tran, info.SkuClassID, "3000", this.dataBaseID[0]))
                        {
                            skuClassInfo = new SkuClassInfo {
                                SkuClassID = info.SkuClassID,
                                OwnerID = "3000",
                                Descr = info.Udf9,
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            skuClassDA.InsertSkuClass(dataBase, tran, skuClassInfo, this.dataBaseID);
                        }
                        if (!skuClassDA.CheckSkuClassIDUnique(dataBase, tran, info.SkuClassID, "9000", this.dataBaseID[0]))
                        {
                            skuClassInfo = new SkuClassInfo {
                                SkuClassID = info.SkuClassID,
                                OwnerID = "9000",
                                Descr = info.Udf9,
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            skuClassDA.InsertSkuClass(dataBase, tran, skuClassInfo, this.dataBaseID);
                        }
                        info.Udf9 = "";
                    }
                    if (info.ReorderQty != 0M)
                    {
                        skuInfoEx.ReorderQty = info.ReorderQty;
                    }
                    if (!string.IsNullOrEmpty(info.SkuStyle))
                    {
                        skuInfoEx.SkuStyle = info.SkuStyle;
                    }
                    if (!string.IsNullOrEmpty(info.Udf10))
                    {
                        AlternateSkuInfo altSku;
                        if (!alternateDA.CheckAlternateSkuIDUnique("1000", info.SkuID, info.Udf10, "", this.dataBaseID[0]))
                        {
                            altSku = new AlternateSkuInfo {
                                OwnerID = "1000",
                                SkuID = info.SkuID,
                                AltSkuID = info.Udf10,
                                VendorID = "",
                                PackID = "STD",
                                DefaultUomID = "EA",
                                Type = "Vendor",
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            alternateDA.InsertAlternateSku(dataBase, tran, altSku, this.dataBaseID);
                        }
                        if (!alternateDA.CheckAlternateSkuIDUnique("3000", info.SkuID, info.Udf10, "", this.dataBaseID[0]))
                        {
                            altSku = new AlternateSkuInfo {
                                OwnerID = "3000",
                                SkuID = info.SkuID,
                                AltSkuID = info.Udf10,
                                VendorID = "",
                                PackID = "STD",
                                DefaultUomID = "EA",
                                Type = "Vendor",
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            alternateDA.InsertAlternateSku(dataBase, tran, altSku, this.dataBaseID);
                        }
                        if (!alternateDA.CheckAlternateSkuIDUnique("9000", info.SkuID, info.Udf10, "", this.dataBaseID[0]))
                        {
                            altSku = new AlternateSkuInfo {
                                OwnerID = "9000",
                                SkuID = info.SkuID,
                                AltSkuID = info.Udf10,
                                VendorID = "",
                                PackID = "STD",
                                DefaultUomID = "EA",
                                Type = "Vendor",
                                IsActive = "Y",
                                CreatedBy = "WebService",
                                UpdatedBy = "WebService",
                                CreatedDate = DateTime.Now,
                                UpdatedDate = DateTime.Now
                            };
                            alternateDA.InsertAlternateSku(dataBase, tran, altSku, this.dataBaseID);
                        }
                        info.Udf10 = "";
                    }
                    skuInfoEx.UpdatedBy = "CEAWebService";
                    skuInfoEx.UpdatedDate = DateTime.Now;
                    skuDA.UpdateSku(dataBase, tran, skuInfoEx, this.dataBaseID);
                    edilogInfo = new EdiLogInfo {
                        WhID = "",
                        LogDate = DateTime.Now,
                        IsSuccess = "成功",
                        LogDescr = "货品" + skuInfoEx.SkuID + "更新成功",
                        UserID = "CEAWebService",
                        Udf1 = "更新",
                        Udf2 = "货品名称:" + skuInfoEx.SkuID,
                        Udf3 = "货品资料",
                        Udf4 = "产品描述:" + skuInfoEx.Descr
                    };
                    edilogInfoList.Add(edilogInfo);
                    skuID = "OK";
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                edilogInfoList = new List<EdiLogInfo>();
                edilogInfo = new EdiLogInfo {
                    WhID = "",
                    LogDate = DateTime.Now,
                    IsSuccess = "异常"
                };
                if (skuInfoEx != null)
                {
                    edilogInfo.LogDescr = "货品" + skuInfoEx.SkuID + "更新失败:" + ex.Message;
                    edilogInfo.Udf2 = "货品名称:" + skuInfoEx.SkuID;
                    edilogInfo.Udf4 = "产品描述:" + skuInfoEx.Descr;
                }
                else
                {
                    edilogInfo.LogDescr = "货品" + strSkuID + "更新失败:" + ex.Message;
                    edilogInfo.Udf2 = "货品名称:" + strSkuID;
                    edilogInfo.Udf4 = "产品描述:" + strOwnerID;
                }
                edilogInfo.UserID = "CEAWebService";
                edilogInfo.Udf1 = "更新";
                edilogInfo.Udf3 = "货品资料";
                edilogInfoList.Add(edilogInfo);
                skuID = ex.Message;
            }
            finally
            {
                edilogDA.InsertEdiLogs(edilogInfoList);
                conn.Close();
            }
            return skuID;
        }
    }
}

